/*
 *  hihocoder.com
 *
 *  Category: Sort
 */

/*-------- Includes --------*/
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

/*-------- Defines --------*/
#define INF 1000000000

/*-------- Types --------*/
typedef long long ll;

/*-------- Global Variables --------*/
int N;
pair<ll, int> P[100002];

/*-------- Function Prototypes --------*/
bool comp(const pair<ll, int> &a, const pair<ll, int> &b);

/*-------- Main Function --------*/
int main(int argc, char const *argv[])
{
    cin >> N;

    int w;
    ll  x, y;
    for (int i = 0; i < N; ++i) {
        cin >> x >> y >> w;

        P[i].first  = x * x + y * y;
        P[i].second = w;
    }

    sort(P, P + N, comp);

    ll sum = 0, maxi = -INF;
    for (int i = 0; i < N; ++i) {
        sum += P[i].second;

        if (sum > maxi) maxi = sum;
    }

    cout << maxi << endl;

    return 0;
}

/*-------- Functions --------*/
bool comp(const pair<ll, int> &a, const pair<ll, int> &b)
{
    return a.first < b.first;
}
